package com.zxn.mymoneykeyboard;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.zxn.keyboard.CustomKeyboardLayout;
import com.zxn.keyboard.SystemKeyboard;


public class AmountInputActivity extends AppCompatActivity {
    private ConstraintLayout main;
    //    private TitleBarView tbvTitle;
    private TextView tvRechargeVal;
    private EditText etRechargeVal;
    private TextView tvRmb;
    private TextView tvDesc;
    private TextView tvAmount;
    private TextView tvAmountRmb;
    private Button btnPutMoney;

    public static void jumpTo(Activity context) {
        context.startActivity(new Intent(context, AmountInputActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        initSubViews();
    }

    protected int getLayoutId() {
        return R.layout.activity_amount_input;
    }

    protected void initSubViews() {
        initView();
    }

    private void initView() {
        CustomKeyboardLayout sysKeyboard = findViewById(R.id.sysKeyboard);
        main = findViewById(R.id.main);
//        tbvTitle = (TitleBarView) findViewById(R.id.tbvTitle);
        tvRechargeVal = findViewById(R.id.tvRechargeVal);
        etRechargeVal = findViewById(R.id.etRechargeVal);

        sysKeyboard.setEditText(etRechargeVal);
        etRechargeVal.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s)) {
                    tvAmount.setText("0.00");
                } else {
                    tvAmount.setText(s.toString());
                }
            }
        });
        tvRmb = (TextView) findViewById(R.id.tvRmb);
        tvDesc = (TextView) findViewById(R.id.tvDesc);
        tvAmount = (TextView) findViewById(R.id.tvAmount);
        tvAmountRmb = (TextView) findViewById(R.id.tvAmountRmb);
        btnPutMoney = (Button) findViewById(R.id.btnPutMoney);
        btnPutMoney.setOnClickListener(v -> {
            String amount = etRechargeVal.getText().toString();
            if (TextUtils.isEmpty(amount)) {
                showMsg("请输入金额!");
                return;
            }
        });
    }

    private void showMsg(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }
}